package com.igeek.rowmapper;

import com.igeek.entity.Employee;
import com.igeek.util.DateTimeUtil;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

public class EmpMapper implements RowMapper<Employee> {

    @Override
    public Employee mapRow(ResultSet resultSet, int i) throws SQLException {
        Employee employee = new Employee();
        employee.setEmpId(resultSet.getInt(1));
        employee.setEmpName(resultSet.getString(2));
        employee.setHireDate(resultSet.getDate(3));
        employee.setSalary(resultSet.getDouble(4));
        employee.setHireDateString(DateTimeUtil.convertToString(employee.getHireDate(), "yyyy-MM-dd"));
        return employee;
    }
}
